//
//  SC_GroupDetail_UserList_Cell.swift
//  APSwift
//
//  Created by jianbo.pei on 2023/4/16.
//

import UIKit
import Kingfisher

class SC_GroupDetail_UserList_Cell: APBaseTableViewCell {
    private var avatarImageView: UIImageView!
    private var nicknameLabel: UILabel!
    
    override func initUI() {
        super.initUI()
        
        contentView.backgroundColor = .clear
        
        avatarImageView = UIImageView().then({ make in
            contentView.addSubview(make)
            make.layer.masksToBounds = true
            make.layer.cornerRadius = 27
        })
        
        nicknameLabel = .ap.lb(.ap.medium(15), .ap.hex("191702")).then({ make in
            contentView.addSubview(make)
        })
    }
    
    override func makeConstraints() {
        super.makeConstraints()
        avatarImageView.snp.makeConstraints { make in
            make.size.equalTo(54)
            make.left.equalTo(10)
            make.centerY.equalToSuperview()
        }
        
        nicknameLabel.snp.makeConstraints { make in
            make.left.equalTo(avatarImageView.snp.right).offset(10)
            make.centerY.equalTo(avatarImageView)
        }
    }
    
    override func setup(_ model: Any?) {
        guard let user = model as? SC_GroupDetail_UserModel else { return }
        if let avatar = user.avatar, !avatar.isEmpty {
            avatarImageView.kf.setImage(with: URL(string: avatar))
        }
        nicknameLabel.text = user.nickname
    }
    
}

extension SC_GroupDetail_UserList_Cell: APView_Height_Protocol {
    static func viewHeight(with model: Any?) -> CGFloat {
        return 78
    }
}
